﻿using System.Security.Claims;
using BilbilBLL;
using Common;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace bilbil.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CollectionController : ControllerBase
    {
        /// <summary>
        /// 根据用户信息id和视频信息id添加关注记录
        /// </summary>
        /// <param name="userInfoId"></param>
        /// <param name="videoInfoId"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public IActionResult AddCollectionInfo(int videoInfoId)
        {
            int userInfoId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            return new JsonResult(new CollectionServer().AddCollectionInfo(userInfoId, videoInfoId));
        }
        /// <summary>
        /// 根据用户信息id和视频信息id删除关注记录
        /// </summary>
        /// <param name="userInfoId"></param>
        /// <param name="videoInfoId"></param>
        /// <returns></returns>
        [HttpDelete]
        [Authorize]
        public IActionResult DeleteCollectionInfo(int videoInfoId)
        {
            int userInfoId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            return new JsonResult(new CollectionServer().DeleteCollectionInfo(userInfoId, videoInfoId));
        }
    }
}
